<?php
namespace Admin\Controller;
use Think\Controller;
use Org\Net\Http;
class RecommendController extends Controller {
    public function index(){
    	$recommend = D("Recommend");
    	$list = $recommend ->select();
    	$this->assign('list',$list);
    	$this->display();
    }
    public function add(){
    	if(IS_POST){
    		$recommend = M("Recommend");
    		$type = I('type') ==''?"Scenic":I('type');
    		$scenic = D($type);
    		$arr = $scenic->where(array('id'=>I('content')))->find();
    		$data = $_POST;
    		$data['name'] = $arr['name'];
    		$data['image'] = split(",", $arr['image'])[0];
    		$result = $recommend->add($data);
    		if($result){
    			$this->success("添加成功",U("Recommend/index"));
    		}else{
    			$this->error("添加失败");
    		}
    	}else{
//     		$type = I('type') ==''?"Scenic":I('type');
//     		if(!S($type)){
// 	    		$scenic = D($type);
//     			$list = $scenic->select();
//     			S($type,$list);
//     		}
    		
//     		$this->assign('list',S($type));
    		$this->display();
    	}
    }
    public function getContent(){
    	$type = I('type') ==''?"Scenic":I('type');
    	if(!S($type)){
    		$scenic = D($type);
    		$list = $scenic->select();
    		S($type,$list);
    	}
    	$this->ajaxReturn(S($type));
    }
}